package com.rds.web.controller.pms;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rds.common.annotation.Log;
import com.rds.common.enums.BusinessType;
import com.rds.system.domain.RdaForm;
import com.rds.system.service.IRdaFormService;
import com.rds.common.core.controller.BaseController;
import com.rds.common.core.domain.AjaxResult;
import com.rds.common.utils.poi.ExcelUtil;
import com.rds.common.core.page.TableDataInfo;

/**
 * from表单Controller
 *
 * @author rds
 * @date 2021-04-19
 */
@RestController
@RequestMapping("/pms/form")
public class RdaFormController extends BaseController
{
    @Autowired
    private IRdaFormService rdaFormService;

    /**
     * 查询from表单列表
     */
    @PreAuthorize("@ss.hasPermi('pms:form:list')")
    @GetMapping("/list")
    public TableDataInfo list(RdaForm rdaForm)
    {
        startPage();
        List<RdaForm> list = rdaFormService.selectRdaFormList(rdaForm);
        return getDataTable(list);
    }

    /**
     * 导出from表单列表
     */
    @PreAuthorize("@ss.hasPermi('pms:form:export')")
    @Log(title = "from表单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RdaForm rdaForm)
    {
        List<RdaForm> list = rdaFormService.selectRdaFormList(rdaForm);
        ExcelUtil<RdaForm> util = new ExcelUtil<RdaForm>(RdaForm.class);
        return util.exportExcel(list, "form");
    }

    /**
     * 获取from表单详细信息
     */
    @PreAuthorize("@ss.hasPermi('pms:form:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rdaFormService.selectRdaFormById(id));
    }

    /**
     * 新增from表单
     */
    @PreAuthorize("@ss.hasPermi('pms:form:add')")
    @Log(title = "from表单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdaForm rdaForm)
    {
        return toAjax(rdaFormService.insertRdaForm(rdaForm));
    }

    /**
     * 修改from表单
     */
    @PreAuthorize("@ss.hasPermi('pms:form:edit')")
    @Log(title = "from表单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdaForm rdaForm)
    {
        return toAjax(rdaFormService.updateRdaForm(rdaForm));
    }

    /**
     * 删除from表单
     */
    @PreAuthorize("@ss.hasPermi('pms:form:remove')")
    @Log(title = "from表单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rdaFormService.deleteRdaFormByIds(ids));
    }
}
